package com.cy.pj.activity.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cy.pj.activity.pojo.Activity;
import com.cy.pj.activity.service.ActivityService;

@Controller
@RequestMapping("/activity/")
public class ActivityController {

    @Autowired
    private ActivityService activityService;
    /**
     * 	基于此方法返回activity页面
     * @return
     */
    @GetMapping("doActivityUI")
    public String doActivityUI() {
        return "activity";
    }

    @PostMapping("doSaveActivity")
    @ResponseBody
    public String doSaveActivity(Activity entity) {
       // System.out.println(entity);//假如希望这样检查对象内容,则需要重写对象的toString方法
        activityService.saveActivity(entity);
        //return  "activity";//这样返回，刷新的是整个页面
      //  System.out.println("ABCD");
        return "save ok";
    }

    @GetMapping("doFindActivitys")
    @ResponseBody //告诉spring 框架将返回值对象转换为json格式字符串
    public List<Activity> doFindActivitys(){
        // Thread.sleep(5000);

        return activityService.findActivitys();
    }

}
